<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增礼券</title>
    <link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox" id="tabbox">
        <div class="main-container">
            <div class="main-container">
            
				  <div class="layui-form-item" id="date-range">
				    <label class="layui-form-label">有效日期</label>
				    <div class="layui-input-inline">
				      <input type="text" name="begin_date" value="{$one['begin_date']}" autocomplete="off" id="start-date" class="layui-input" placeholder="开始日期">
				    </div>
				    <label class="layui-form-label">-</label>
				     <div class="layui-input-inline">
				      <input type="text" name="end_date" value="{$one['end_date']}" autocomplete="off" id="end-date" class="layui-input" placeholder="结束日期">
				    </div>
				  </div>
				  
				 <div class="layui-form-item">
				    <label class="layui-form-label">礼券编号</label>
				    <div class="layui-input-inline">
				      <input type="text" name="gift_no"	value="{$one['giftcert_no']}" maxlength="20" required  lay-verify="required" placeholder="请输入礼券编号" autocomplete="off" class="layui-input">
				    </div>
				    
				    <label class="layui-form-label">礼券类型</label>
				    <div class="layui-input-inline">
				      <input type="text" name="gift_type" value="{$one['gift_type']}" required  lay-verify="required" placeholder="请输入礼券类型" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  
				 <div class="layui-form-item">
				    <label class="layui-form-label">礼券状态</label>
				    <div class="layui-input-inline">
				      <select name="status" id='status'>
				            <option {if condition="$one['status'] eq '1'"}selected="selected"{/if} value="1">可用</option>
                            <option {if condition="$one['status'] eq '2'"}selected="selected"{/if} value="2">不可用</option>
                            <option {if condition="$one['status'] eq '3'"}selected="selected"{/if} value="3">已用</option>
				         </select>
				    </div>
				    
				    <label class="layui-form-label">发放门店</label>
				    <div class="layui-input-inline">
				      <input type="text" name="send_branch" value="{$one['send_branch']}" id="branch_no" placeholder="请输入分店编码" onfocus="showBranchs()" autocomplete="off" class="layui-input">
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">面值</label>
				    <div class="layui-input-inline">
				      <input name="gift_money" value="{$one['gift_money']}" placeholder="100.00" class="layui-input" autocomplete="off"/>
				    </div>
				    
				    <label class="layui-form-label">发放人</label>
				    <div class="layui-input-inline">
				      <input type="text" id="operator" value="{$one['oper_id']}" name="oper_id" class="layui-input" onfocus="showOperators()" autocomplete="off"/>
				    </div>
				  </div>

				  <input name="add" type="hidden" value="{$act}"/>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="gift-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="__STATIC__/lib/layui/layui.js"></script>
<script src="__PEAR__/component/pear/pear.js"></script>
<script src="__STATIC__/js/admin/common.js"></script>
<script>
layui.use(['form','jquery','common','laydate'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    let laydate = layui.laydate;
    
    var path="/{$MODULE_NAME}/gift";
	var _url="/add";
	var branchs_url="{:U('Controls/branchs')}";
	var operator_url="{:U('Controls/operators')}";
	
	laydate.render({
	    elem: '#date-range'
	    ,range: ['#start-date', '#end-date']
	});
	
	//显示分店选择框
	window.showBranchs=function(){
		_layerIndex=openWin("分店选择",branchs_url,"800px","450px");
	}
	
	//门店选择后的回调函数
	window.callBackBranch=function(data){
		
		var arr=new Array();
		for(var i in data){
			arr.push(data[i]['branch_no']);
		}
		
		$("#branch_no").val(arr.join(","));
		
		if(_layerIndex!=null){
			layer.close(_layerIndex);
		}
		_layerIndex=null;
	}
	
	//显示操作员选择框
	window.showOperators=function(){
		_layerIndex=openWin("操作员选择",operator_url,"800px","450px");
	}
	
	//操作员选择后的回调函数
	window.callBackOprator=function(data){
		
		$("#operator").val(data[0]['oper_id']);
		
		if(_layerIndex!=null){
			layer.close(_layerIndex);
			_layerIndex=null;
		}
	}
	
    form.on('submit(gift-save)', function(data){
        $.ajax({
            url:path+_url,
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code){
                    layer.msg(result.msg,{icon:1,time:2000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("gift-table");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:2000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>